package com.yjz.log_study;

import ch.qos.logback.core.joran.spi.JoranException;
import lombok.extern.slf4j.Slf4j;
import org.junit.Test;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.net.URL;

@Slf4j
public class LogStudy {
  @Test
  public void testClassLoder() {
    URL url = LogStudy.class.getClassLoader().getResource("logback.xml");
    System.out.println(url);
  }

  @Test
  public void logbackTest() throws JoranException {
    /**
     * 若logback.xml 不直接在classpath下，则可以用如下方式手动加载logback.xml
     */
     	/*Logger log = LoggerFactory.getLogger(LogStudy.class);
		LoggerContext context=(LoggerContext) LoggerFactory.getILoggerFactory();
		JoranConfigurator configurator=	new JoranConfigurator();
		configurator.setContext(context);
		context.reset();
		configurator.doConfigure(LogStudy.class.getClassLoader().getResource("configure/logback.xml"));*/
// 	Logger log = LoggerFactory.getLogger(LogStudy.class);
    log.trace("========= 0级 trace");
    log.debug("========= 1级 debug");
    log.info("========= 2级 info");
    log.warn("========= 3级 warn");
    log.error("========= 4级 error{}", "yjz");
//		//打印 Logback 内部状态
//		LoggerContext c=(LoggerContext)LoggerFactory.getILoggerFactory();
//		StatusPrinter.print(c);
  }
}
